let app = new Vue({
	el: "#app",

	data() {
		var validatePass = (rule, value, callback) => {
			if (value === '') {
				callback(new Error('请输入密码'));
			} else {
				if (this.pwchangeForm.ConfirmPassword !== '') {
					this.$refs.pwchangeForm.validateField('ConfirmPassword');
				}
				callback();
			}
		};
		var validatePass2 = (rule, value, callback) => {
			if (value === '') {
				callback(new Error('请再次输入密码'));
			} else if (value !== this.pwchangeForm.Password) {
				callback(new Error('两次输入密码不一致!'));
			} else {
				callback();
			}
		};
		return {
			rules: {
				Password: [{
						required: true,
						message: '请输入密码',
						trigger: 'blur'
					},
					{
						validator: validatePass,
						trigger: 'blur'
					},
					{
						min: 6,
						max: 6,
						message: '长度6 个字符',
						trigger: 'blur'
					}

				],
				ConfirmPassword: [{
						required: true,
						message: '请再次输入密码',
						trigger: 'blur'
					},
					{
						min: 6,
						max: 6,
						message: '长度6 个字符',
						trigger: 'blur'
					},
					{
						validator: validatePass2,
						trigger: 'blur'
					},
				],
			},

			pwchangeForm: {
				userid: localStorage.getItem('USERID'),
				Password: "",
				ConfirmPassword: "",
			},

			loaded: false,
		}

	},
	methods: {
		// 确认
		async confirm() {
			console.log(this.pwchangeForm)
			// this.$refs.pwchangeForm.validate((valid) => {
			// 	if (valid) {
			this.$refs.pwchangeForm.validate(async valid => {
				if (valid) {
					try {
						res = await axios.put('api/user/updatepassword', this.pwchangeForm);
						if (res.code === 200) {
							console.log(res)
							this.$message.success(res.message);
							//this.users = res.data;
						} else {
							this.$message.error(res.message);
						}
					} catch (e) {
						this.$message.error('修改密码请求出错！', e.message);
					}
				}
			})
		},
	},

	async mounted() {

	},
});
